package com.gggd.aopdemo.util;

import lombok.Data;

/**
 * @Author 施瑞贤
 * @email shiruixian@zhongruigroup.com
 * @date 2021/9/28 16:36
 */
@Data
public class WebApiResult<T> {

    private Boolean success;

    private String message;

    private int code;

    private T data;

    /**
     * 操作成功
     * @param message
     * @param data
     * @return
     */
    public static WebApiResult ok(String message,Object data){
        WebApiResult result = new WebApiResult();
        result.setSuccess(true);
        result.setMessage(message);
        result.setCode(200);
        result.setData(data);
        return result;
    }

    /**
     * 操作成功
     * @param message
     * @return
     */
    public static WebApiResult ok(String message){
        WebApiResult result = new WebApiResult();
        result.setSuccess(true);
        result.setMessage(message);
        result.setCode(200);
        result.setData(null);
        return result;
    }

    /**
     * 操作失败
     * @param message
     * @return
     */
    public static WebApiResult error(String message){
        WebApiResult result = new WebApiResult();
        result.setSuccess(false);
        result.setMessage(message);
        result.setCode(0);
        result.setData(null);
        return result;
    }
}
